package org.yray.sip.server;

import lombok.extern.slf4j.Slf4j;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;


@Slf4j
public class SipExtTable {

    private Map<String,String> extMap=new HashMap<>();
    private Set<String> ableExtNoSet= new HashSet<>();
    private ReentrantLock lock=new ReentrantLock();
    private List<String> extList=new ArrayList<>();
    private AtomicInteger currIndex=new AtomicInteger(0);

    public void addExtNo(String ext)
    {
        log.info("add to list ={}", ext);
        extList.add(ext);
    }

    public void putExt(String ext,String password)
    {

        extMap.put(ext,password);

    }
    public String getExtPassword(String ext)
    {
        return extMap.get(ext);
    }


    public void putBackNew(String extNo,String key)
    {
        log.info("key={},putBackNew={}", key,extNo);
    }

    public String getAbleExtNoNew(String key)
    {

        int index=currIndex.incrementAndGet();
        String extNo= extList.get(index%extList.size());
        log.info("key={},getAbleExtNoNew={}", key,extNo);
        return extNo;
    }

}
